Skip to content

EDM-3535: Correct isRHEM detection for OCP plugin#694

Merged
celdrake merged 2 commits into
flightctl:mainfrom
celdrake:EDM-3535-fix-ocp-plugin-docs
Jun 29, 2026
Merged

EDM-3535: Correct isRHEM detection for OCP plugin#694
celdrake merged 2 commits into
flightctl:mainfrom
celdrake:EDM-3535-fix-ocp-plugin-docs

Conversation

@celdrake

@celdrake celdrake commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

The OCP plugin did not receive the "settings" therefore the "isRHEM" detection didn't work there.

Areas affected

  • apps/ocp-plugin/: Platform-specific OCP plugin frontend
  • proxy/: Go auth proxy backend (UI settings endpoint + RHEM index selection)
  • libs/ui-components/: Read-only impact (consumers depend on settings.isRHEM)

Summary

This PR fixes isRHEM detection for the OCP plugin by exposing runtime UI settings from the Go proxy and consuming them in the plugin’s app context.

apps/ocp-plugin/

  • Updated apps/ocp-plugin/src/components/AppContext/AppContext.tsx:
    • Added a local useUiSettings() hook that initializes isRHEM from window.isRHEM, then fetches ${apiProxy}/ui-settings (AbortController-protected).
    • Coerces data.isRHEM to a boolean (!!data.isRHEM), writes it back to window.isRHEM, and updates React state; defaults remain if the fetch fails/aborts.
    • useValuesAppContext now provides settings: { isRHEM: boolean } instead of a hardcoded empty settings object.
  • Updated apps/ocp-plugin/src/utils/apiCalls.ts:
    • uiProxy is now exported so other modules can reuse the computed UI proxy base URL.

proxy/

  • Updated proxy/config/config.go:
    • IsRHEM now parses IS_RHEM as a boolean (parseBoolEnv("IS_RHEM", false)).
  • Added proxy/server/settings.go:
    • Introduces UISettingsHandler, returning JSON { "isRHEM": <bool> } sourced from config.IsRHEM.
  • Updated proxy/app.go:
    • Conditionally registers GET /api/ui-settings only when config.OcpPlugin == "true".
  • Updated proxy/server/server.go:
    • serveIndexPage now checks config.IsRHEM as a boolean to choose between index and index-rhem.

Cross-cutting implications

  • The OCP plugin now relies on a new runtime proxy endpoint (/api/ui-settings) to determine isRHEM, aligning plugin behavior with server/env configuration.
  • While this PR does not modify libs/ui-components/, it enables consistent settings.isRHEM availability to components that already consume it.
  • No changes were made to libs/types/, libs/i18n/, libs/cypress/, apps/standalone/, packaging, container builds, or CI/E2E configuration.

@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

Backend now serves a JSON UI settings endpoint with an isRHEM boolean; the frontend exports uiProxy, fetches that endpoint on mount, stores the value in window.isRHEM, and exposes it through AppContext.

Changes

UI Settings Endpoint and Frontend Integration

Layer / File(s) Summary
Backend config and UI settings handler
proxy/config/config.go, proxy/server/settings.go, proxy/server/server.go, proxy/app.go
Parses IS_RHEM as a boolean; adds UISettingsHandler that returns JSON { isRHEM: bool }; registers GET /api/ui-settings when OcpPlugin is enabled; index selection uses boolean IsRHEM.
Frontend hook and api proxy export
apps/ocp-plugin/src/utils/apiCalls.ts, apps/ocp-plugin/src/components/AppContext/AppContext.tsx
Exports uiProxy; adds useUiSettings() which initializes from window.isRHEM, fetches ${apiProxy}/ui-settings with abort support, normalizes and stores isRHEM in state and window, and returns settings via useValuesAppContext().

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

ocp-plugin, proxy

Poem

A tiny flag from env to JSON flows,
The UI asks, the proxy knows.
A boolean travels, crisp and bright,
From server truth to AppContext light.

🚥 Pre-merge checks | ✅ 13 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Unchecked-Errors ⚠️ Warning FAIL: proxy/server/settings.go silently returns on w.Write failure, and proxy/bridge has unannotated _= error ignores. Log or otherwise handle the write/close failures, or add comments explaining why each ignored error is safe to drop.
✅ Passed checks (13 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and accurately summarizes the main change: fixing isRHEM detection for the OCP plugin.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
No-Hardcoded-Secrets ✅ Passed No hardcoded secrets, embedded credentials, or long base64 literals were found in the touched files; only runtime/env-derived values appear.
No-Weak-Crypto ✅ Passed Reviewed all touched files; no weak algorithms, custom crypto, or secret/token comparisons were introduced. The only crypto import is standard crypto/tls.
No-Injection-Vectors ✅ Passed The changed TS/Go files only fetch/serve JSON and static content; no eval/exec, dangerous HTML, shell calls, or unsafe YAML usage were added.
Container-Privileges ✅ Passed The PR only changes app/proxy code; no container/K8s manifests or privileged flags (privileged, hostPID/Network/IPC, SYS_ADMIN, allowPrivilegeEscalation) were added.
No-Sensitive-Data-In-Logs ✅ Passed No new log statements expose secrets/PII; the new UI-settings path returns only a boolean and the added client fetch does not log data.
Resource-Leaks ✅ Passed PASS: The touched Go files add only route/env/json logic; no new file, body, or network handles are opened, and no goroutines are introduced.
Ai-Attribution ✅ Passed HEAD includes the acceptable AI attribution trailer “Made-with: Cursor” and no Co-Authored-By trailer was found.
Generated-Files-Not-Hand-Edited ✅ Passed The PR touches app/proxy source files only; no modified paths fall under the generated-file directories or translation.json.
I18n-Compliance ✅ Passed The changed .tsx file has no user-visible JSX text and no t() calls at all, so there are no i18n issues to flag.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.12.2)

level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies"

🔧 OpenGrep (1.23.0)
apps/ocp-plugin/src/components/AppContext/AppContext.tsx

┌──────────────┐
│ Opengrep CLI │
└──────────────┘

�[32m✔�[39m �[1mOpengrep OSS�[0m
�[32m✔�[39m Basic security coverage for first-party code vulnerabilities.

[00.13][ERROR]: unable to find a config; path .coderabbit-opengrep-fallback.yml does not exist

apps/ocp-plugin/src/utils/apiCalls.ts

┌──────────────┐
│ Opengrep CLI │
└──────────────┘

�[32m✔�[39m �[1mOpengrep OSS�[0m
�[32m✔�[39m Basic security coverage for first-party code vulnerabilities.

[00.19][ERROR]: unable to find a config; path .coderabbit-opengrep-fallback.yml does not exist

proxy/config/config.go

┌──────────────┐
│ Opengrep CLI │
└──────────────┘

�[32m✔�[39m �[1mOpengrep OSS�[0m
�[32m✔�[39m Basic security coverage for first-party code vulnerabilities.

[00.31][ERROR]: unable to find a config; path .coderabbit-opengrep-fallback.yml does not exist

  • 3 others

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@proxy/config/config.go`:
- Around line 27-29: IsRHEMEnabled is an exported function lacking a godoc
comment; add a concise godoc comment immediately above the IsRHEMEnabled
function explaining what it checks (reads the IS_RHEM env var) and what the
boolean return value represents (true when IS_RHEM == "true", false otherwise),
so the exported API is properly documented for users and tools.

In `@proxy/server/settings.go`:
- Line 19: The call to json.NewEncoder(w).Encode(settings) currently ignores its
error; modify the handler that writes settings (the code using
json.NewEncoder(w).Encode(settings), referencing variables w and settings) to
check the returned error, log or record it, and return an appropriate HTTP error
status instead of silently continuing: if Encode fails, write a 500 response
(e.g., http.Error or w.WriteHeader(500) + an error body) and ensure no 200
response is sent; otherwise continue to write the successful JSON as before.
- Around line 14-20: The UISettingsHandler currently serves a top-level public
endpoint and swallows the JSON encode error; add an explicit comment above
UISettingsHandler documenting that this endpoint is intentionally public
(registered on router, not apiRouter), that it only exposes the deployment-wide
flag returned by config.IsRHEMEnabled() and must never include org/user-specific
data, or alternatively move its registration to apiRouter if it should require
middleware.AuthMiddleware/middleware.OrganizationMiddleware; then fix the
ignored encoder error by capturing the return value from
json.NewEncoder(w).Encode(settings) and handling it (log via your existing
logger and respond with an appropriate http error/status if encoding fails).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Enterprise

Run ID: 62afc2cc-db3c-4815-951b-e2d4e235dd8a

📥 Commits

Reviewing files that changed from the base of the PR and between d6bed50 and 0ef5621.

📒 Files selected for processing (5)
  • apps/ocp-plugin/src/components/AppContext/AppContext.tsx
  • apps/ocp-plugin/src/utils/apiCalls.ts
  • proxy/app.go
  • proxy/config/config.go
  • proxy/server/settings.go

Comment thread proxy/config/config.go Outdated
Comment thread proxy/server/settings.go
Comment thread proxy/server/settings.go Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@proxy/server/settings.go`:
- Around line 17-23: The handler currently streams JSON directly with
json.NewEncoder(w).Encode(settings), which can commit a 200 before Encode fails;
instead marshal the payload first (e.g., json.Marshal or json.MarshalIndent)
into a byte slice, check the error, and only after successful marshal set the
Content-Type header and write the bytes to w (optionally set Content-Length).
Update the uiSettings write path to replace json.NewEncoder(w).Encode(settings)
with pre-marshalling and return http.Error(..., http.StatusInternalServerError)
only if marshal fails.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Enterprise

Run ID: 6476b5d1-52f4-4a89-bb29-abde8634e7fa

📥 Commits

Reviewing files that changed from the base of the PR and between 0ef5621 and 8de39cf.

📒 Files selected for processing (5)
  • apps/ocp-plugin/src/components/AppContext/AppContext.tsx
  • proxy/app.go
  • proxy/config/config.go
  • proxy/server/server.go
  • proxy/server/settings.go

Comment thread proxy/server/settings.go Outdated
@celdrake celdrake force-pushed the EDM-3535-fix-ocp-plugin-docs branch from 8de39cf to 39aaf8e Compare June 12, 2026 13:47

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@proxy/server/settings.go`:
- Around line 26-27: The write error from w.Write(payload) is being ignored;
update the handler containing the w.Write call to log the error before returning
— e.g., capture err from w.Write(payload), call the existing logger (or the
standard log package) like logger.Errorf("write response failed: %v", err) or
log.Printf(...) and then return; reference the w.Write(payload) expression and
its enclosing function to locate where to add the logging.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Enterprise

Run ID: 91948f37-6167-4d43-8057-7885a037508c

📥 Commits

Reviewing files that changed from the base of the PR and between 8de39cf and 39aaf8e.

📒 Files selected for processing (5)
  • apps/ocp-plugin/src/components/AppContext/AppContext.tsx
  • proxy/app.go
  • proxy/config/config.go
  • proxy/server/server.go
  • proxy/server/settings.go

Comment thread proxy/server/settings.go

@jkilzi jkilzi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solid fix. The two-part approach (Go bool + runtime /ui-settings fetch) is the right solution for OCP plugin RHEM detection.

Go side: converting IS_RHEM from getEnvVar (string) to parseBoolEnv (bool) eliminates the fragile == "true" check in serveIndexPage. Clean.

Frontend: useUiSettings correctly seeds from window.isRHEM as a fallback and uses AbortController for effect cleanup — no memory leak. Error is swallowed silently which is the right choice for a non-critical settings fetch.

Note — auth: /ui-settings returns isRHEM with no explicit auth check. This is fine since the entire OCP plugin proxy sits behind OpenShift auth anyway.

Nit: the initial useState({ isRHEM: window.isRHEM ?? false }) means that if the RHEM index page already set window.isRHEM = true, there will be a harmless double render (initial true → fetch confirms true). Worth a comment for future readers.

@celdrake celdrake force-pushed the EDM-3535-fix-ocp-plugin-docs branch from 39aaf8e to abe54e1 Compare June 29, 2026 09:14

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@proxy/app.go`:
- Around line 75-77: The /ui-settings route gating in app.go is using a raw
string comparison on config.OcpPlugin, so normalize IS_OCP_PLUGIN before this
branch instead of checking only for "true". Update the config handling in
proxy/config/config.go or the route registration logic in app.go so values like
TRUE, 1, or yes are treated as enabled, and keep the change anchored around the
existing OcpPlugin and UISettingsHandler path registration.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Enterprise

Run ID: 8db72aef-e37c-4fd2-9f37-44fc5c5dd94b

📥 Commits

Reviewing files that changed from the base of the PR and between 39aaf8e and abe54e1.

📒 Files selected for processing (6)
  • apps/ocp-plugin/src/components/AppContext/AppContext.tsx
  • apps/ocp-plugin/src/utils/apiCalls.ts
  • proxy/app.go
  • proxy/config/config.go
  • proxy/server/server.go
  • proxy/server/settings.go

Comment thread proxy/app.go
Comment on lines +75 to +77
if config.OcpPlugin == "true" {
apiRouter.HandleFunc("/ui-settings", server.UISettingsHandler).Methods(http.MethodGet)
} else {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Normalize IS_OCP_PLUGIN before gating this route.

This branch still depends on config.OcpPlugin == "true", but proxy/config/config.go defines OcpPlugin as a raw env string. Values like TRUE, 1, or yes leave /api/ui-settings unregistered, so the OCP plugin falls back to false and the RHEM fix never activates.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@proxy/app.go` around lines 75 - 77, The /ui-settings route gating in app.go
is using a raw string comparison on config.OcpPlugin, so normalize IS_OCP_PLUGIN
before this branch instead of checking only for "true". Update the config
handling in proxy/config/config.go or the route registration logic in app.go so
values like TRUE, 1, or yes are treated as enabled, and keep the change anchored
around the existing OcpPlugin and UISettingsHandler path registration.

@celdrake celdrake merged commit e413c0e into flightctl:main Jun 29, 2026
10 checks passed
@celdrake celdrake deleted the EDM-3535-fix-ocp-plugin-docs branch June 29, 2026 09:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants